#include<iostream>
using namespace std;

#include<cmath>

int main(){

	double h[10];
	for(int i=0;i<10;i++){
		h[i] = pow(0.1,i+1);
	}

	double x = 10;
	double double_derivative;
	double relative_error;

	FILE *fp;
	fp=fopen("double_derivative_ex.txt","w");
	if(fp==NULL){
		cout<<" failed to open double_derivative_ex.txt"<<endl;
		exit(1);
	}

	for(int i=0;i<10;i++){
		double_derivative = ( exp(x+h[i]) + exp(x-h[i]) - 2*exp(x) )/h[i]/h[i];
		relative_error = double_derivative/exp(x) -1 ;
	        cout<<" h= "<<h[i]<<"  relative error = "<< relative_error <<endl;
		fprintf(fp, "%lf \t %lf \n", log10( h[i] ), log10( fabs(relative_error) ) );
	}	
	fclose(fp);

	return 0;
}
